//
//  GSAppUIContentViewController.m
//  GameSky
//
//  Created by lanou on 16/1/21.
//  Copyright © 2016年 NiRongfei. All rights reserved.
//

#import "GSAppUIContentViewController.h"

@interface GSAppUIContentViewController ()

@end

@implementation GSAppUIContentViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];

    self.bar = [[GSCustomNavigationBar alloc]initWithFrame:CGRectMake(0, 0, kScreenWidth, 64)];
    
    [self.bar.leftButton setImage:[UIImage imageNamed:@"common_Icon_Back_20x20_UIMode_Day"] forState:(UIControlStateNormal)];
    
    [self.bar.leftButton addTarget:self action:@selector(leftButtonClick:) forControlEvents:(UIControlEventTouchUpInside)];
    
    [self.view addSubview:self.bar];
    
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panGestureRecognizer:)];
    
    [self.view addGestureRecognizer:pan];

    self.view.layer.shadowRadius = 5;
    self.view.layer.shadowOpacity = 0.5;
    self.view.layer.shadowOffset = CGSizeMake(0, 0);
    self.view.layer.shadowColor = [UIColor blackColor].CGColor;
}

- (void)panGestureRecognizer:(UIPanGestureRecognizer *)recognizer
{
    /**
     *  获得手指当前点
     */
    CGFloat x = [recognizer locationInView:self.view.superview].x;
    
    CGPoint transPoint = [recognizer translationInView:self.view.superview];
    
    CGRect newFrame = self.view.frame;

    if (transPoint.x > 0) {
        
        newFrame.origin.x = transPoint.x;
        
        if (recognizer.state == UIGestureRecognizerStateEnded) {
            
            if (x > kScreenWidth / 2) {
                
                newFrame.origin.x = kScreenWidth;
                
            }else{
                
                newFrame.origin.x = 0;
            }
            
        }

        [UIView animateWithDuration:0.5 animations:^{
            
            self.view.frame = newFrame;
            
        }];

    }

    
}

/**
 *  点击左边按钮返回
 */
- (void)leftButtonClick:(UIButton *)leftButton
{
    [UIView animateWithDuration:0.5 animations:^{
        
        
        self.view.transform = CGAffineTransformTranslate(self.view.transform, kScreenWidth, 0);
        
    }];

}



@end
